package com.uh.calculation.operator;

import com.uh.calculation.bean.FormulaBean;
import com.uh.calculation.bean.OperatorVal;
import com.uh.calculation.bean.TbFeild;
import com.uh.calculation.bean.WarnJiSuanBean;
import com.uh.calculation.util.FormulaUtil;
import com.uh.calculation.util.GetBean;
import com.uh.calculation.util.TimeUtil;
import com.uh.microservice.core.dao.JdbcDao;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 痕迹表  比较变动次数
 */
@Data
public class HjNumOperator {

    private JdbcDao jdbcDao;
    private WarnJiSuanBean warnJiSuanBean;



    public HjNumOperator(JdbcDao jdbcDao, WarnJiSuanBean warnJiSuanBean){
        this.jdbcDao=jdbcDao;
        this.warnJiSuanBean=warnJiSuanBean;

    }


    /**
     * 季报数据
     * 月报数据
     * @param list
     * @return
     */
    public   void jisuan(List<Map<String, Object>> ls , List<OperatorVal> list,String  feildVal ){
        if(ls == null ||  ls.size() == 0 ){
            return;
        }
        this.warnJiSuanBean=warnJiSuanBean;
        Date lastTime = warnJiSuanBean.getLastTime();

        for(OperatorVal operatorVal :list){
            try {
                List<FormulaBean> formulaBeans = operatorVal.getFormulaBeans();//计算公式
                String field = operatorVal.getField();
                List<TbFeild> tbFeilds = GetBean.getTbf(field);
                int num = 0;
                String timeCode = "";
                for (int i = 1; i < ls.size(); i++) {
                    timeCode = ls.get(i).get("EDIT_TIME").toString();
                    try {
                        if (TimeUtil.bj(lastTime, timeCode, warnJiSuanBean.getYear_is_month(), warnJiSuanBean.getIs_hc())) {
                            String META_NAME = ls.get(i).get("META_NAME").toString();
                            if (META_NAME.equals(feildVal)) {
                                num = num + 1;
                            }
                        }
                    } catch (Exception e) {

                    }
                }

                tbFeilds.get(0).setData(num + "");
                //扔进公式解析工具
                new FormulaUtil(tbFeilds, formulaBeans, warnJiSuanBean, operatorVal.getDimension(), timeCode);
            }catch (Exception e){}
        }
    }





}
